$(document).ready(function(e) {
	//全局调用
    $.bg.popup();
});
(function($) {
$.bg = {
	popup: function(_17) {
		var _18 = {selector: ".ui_popup",popupId: "ui_popup",preloadText: "Loading...",errorText: "There has been a problem with your request, please click outside this window to close it.",closeText: "X",prevText: "&laquo; Previous",nextText: "Next &raquo;",opacity: 0.2,hiddenClass: "hidden",callback: function() {
			}};
		if (typeof _17 == "string") {
			_18.selector = _17;
		}
		var _17 = $.extend(_18, _17);
		return $(_17.selector).each(function(i) {
			var obj = this;
			var _19, _1a;
			var _1b = true;
			var _1c = this.tagName.toLowerCase();
			if ($(this).hasClass("ui_gallery")) {
				var _1d = $(this).attr("class");
				_1d = _1d.split(" ").join("");
				$.data(this, "ui_gallery", _1d);
				eval("if((typeof " + _1d + "_arr == \"undefined\")) " + _1d + "_arr= new Array()");
				eval(_1d + "_arr").push($(this));
				$.data(this, "index", eval(_1d + "_arr").length - 1);
			}
			if ($.browser.opera) {
				$.support.opacity = true;
			}
			var ie6 = $.browser.msie && $.browser.version.substr(0, 1) < 7;
			var _1e = $.browser.opera && $.browser.version <= 9.5;
			var w, h, w2, h2;
			var cw, ch;
			cw = ch = 0;
			var _1f = false;
			var _20 = function() {
				w = $(window).width();
				h = $(document).height();
				w2 = $(window).width() / 2;
				h2 = $(window).height() / 2;
				if ($("#" + _17.popupId).length == 0) {
					$("<div id=\"" + _17.popupId + "\"></div>").appendTo("body").css({"width": w,"height": h,"position": "absolute","top": "0","left": "0","z-index": "10000","opacity": _17.opacity}).click(function() {
						_26();
					});
				}
				$("<div id=\"" + _17.popupId + "_preloader\">" + _17.preloadText + "</div>").appendTo("body");
				set($("#" + _17.popupId + "_preloader"));
				$("<div id=\"" + _17.popupId + "_content\"></div>").appendTo("body").css({"visibility": "hidden","position": "absolute","top": "-10000px","left": "-10000px"});
				$("<div id=\"" + _17.popupId + "_inner\"></div>").appendTo("#" + _17.popupId + "_content").css({"overflow": "auto","height": "100%"});
				
				var rel = $(obj).attr("rel").split(";");
				$.each(rel, function(i) {
					if (rel[i].indexOf("width") != -1) {
						cw = rel[i].split(":")[1];
					}
					if (rel[i].indexOf("height") != -1) {
						ch = rel[i].split(":")[1];
					}
				});
				if ($(obj).attr("title") != "") {
					$("<span class=\"caption\">" + $(obj).attr("title") + "</span>").prependTo("#" + _17.popupId + "_content").hide();
				}
				else
				{
					$("<span class=\"caption\">标题</span>").prependTo("#" + _17.popupId + "_content").hide();	
				}
				$("<small id=\"" + _17.popupId + "_close\">" + _17.closeText + "</small>").prependTo("#" + _17.popupId + "_content").click(function() {
					_26();
				});
			};
			var _21 = function() {
				$("#" + _17.popupId + "_preloader").remove();
				var _22 = $("#" + _17.popupId + "_content");
				var fh = false;
				if (cw != 0) {
					$(_22).css("width", parseInt(cw));
				}
				if (ch != 0) {
					$(_22).css("height", parseInt(ch));
					fh = true;
				}
				if ($(_22).width() > ($(window).width() - 50)) {
					$(_22).css("width", $(window).width() - 50);
				}
				if ($(_22).height() > ($(window).height() - 50)) {
					$(_22).css("height", $(window).height() - 50);
					fh = true;
				}
				$(".caption", _22).css({"width": $(_22).width(),"display": "block"});
				if ($(".caption", _22).height() > 0) {
					if (fh) {
						$("#" + _17.popupId + "_inner").height($("#" + _17.popupId + "_inner").height() - $(".caption", _22).outerHeight());
					}
				}
				set($("#" + _17.popupId + "_content"));
				$("#" + _17.popupId + "_content").css("visibility", "visible");
			};
			var set = function(_23) {
				$(_23).css({"text-align": "left","float": "left","position": "fixed","z-index": "10001","visible": "hidden"});
				var _24 = w2 - $(_23).width() / 2;
				var top = h2 - $(_23).height() / 2;
				$(_23).css({"left": _24,"top": top,"display": "none"}).fadeIn("1000");
				if (ie6) {
					$(_23).css({"position": "absolute","top": (top + $(window).scrollTop()) + "px"});
				}
				if (_1e) {
					$(_23).css({"position": "absolute","top": (document.body["clientHeight"] / 2 - $(obj).height() / 2 + $(window).scrollTop()) + "px"});
				}
				if (ie6) {
					$("embed, object, select").css("visibility", "hidden");
				}
			};
			var _25 = function() {
				$("#" + _17.popupId + "_content").text(_17.errorText);
				_21();
			};
			var _26 = function() {
				if (!_1b) {
					$(_19).addClass(_17.hiddenClass).appendTo(_1a);
				}
				$("#" + _17.popupId).remove();
				$("#" + _17.popupId + "_content").remove();
				$("#" + _17.popupId + "_preloader").remove();
				if (ie6) {
					$("embed, object, select").css("visibility", "visible");
				}
				_17.callback();
			};
			if (_1c != "a") {
				_26();
				_20();
				_19 = this;
				_1b = $(_19).is(":visible");
				_1a = $(_19).parent();
				if (_1b) {
					_19 = $(_19).clone();
				}
				$(_19).removeClass(_17.hiddenClass).appendTo("#" + _17.popupId + "_inner").show();
				_21();
			} else {
				$(this).bind("click", function(e) {
					e.preventDefault();
					_26();
					_20();
					var _27 = $(this).attr("href");
					var _28 = _27.substr(_27.lastIndexOf(".")).toLowerCase();
					var _29;
					if ($(this).hasClass("flash")) {
						var _2a = "<object width=\"100%\" height=\"100%\"><param name=\"allowfullscreen\" value=\"true\" /><param name=\"allowscriptaccess\" value=\"always\" /><param name=\"movie\" value=\"" + _27 + "\" /><embed src=\"" + _27 + "\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowscriptaccess=\"always\" width=\"100%\" height=\"100%\"></embed></object>";
						$(_2a).appendTo("#" + _17.popupId + "_inner");
						if (cw == 0) {
							cw = 600;
						}
						if (ch == 0) {
							ch = 400;
						}
						_1f = true;
					} else {
						if (_28 == ".jpg" || _28 == ".jpeg" || _28 == ".gif" || _28 == ".png" || _28 == ".bmp") {
							var img = new Image();
							$(img).error(function() {
								_25();
							}).appendTo("#" + _17.popupId + "_inner");
							img.onload = function() {
								_21();
								_1f = false;
								img.onload = function() {
								};
							};
							img.src = _27 + "?" + (new Date()).getTime() + " =" + (new Date()).getTime();
						} else {
							if (_27.charAt(0) == "#") {
								_19 = $(_27).get(0);
								_1b = $(_19).is(":visible");
								_1a = $(_19).parent();
								if (_1b) {
									_19 = $(_19).clone();
								}
								$(_19).removeClass(_17.hiddenClass).appendTo("#" + _17.popupId + "_inner").show();
								_1f = true;
							} else {
								$("<iframe frameborder=\"0\" scrolling=\"auto\" style=\"width:100%;height:100%\" src=\"" + _27 + "\" />").appendTo("#" + _17.popupId + "_inner");
								if (cw == 0) {
									cw = 900;
								}
								if (ch == 0) {
									ch = 500;
								}
								_1f = true;
							}
						}
					}
					if (_1f) {
						_21();
					}
					if ($(this).hasClass("ui_gallery")) {
						var arr = $.data(this, "ui_gallery");
						arr = eval(arr + "_arr");
						var _2b = $.data(this, "index");
						if (arr.length > 1) {
							$("<div id=\"" + _17.popupId + "_pager\"></div>").appendTo("#" + _17.popupId + "_inner");
							$("<small id=\"" + _17.popupId + "_gallery\"></small>").appendTo("#" + _17.popupId + "_pager");
							$("<small id=\"" + _17.popupId + "_counter\">" + (_2b + 1) + "/" + arr.length + "</small>").appendTo("#" + _17.popupId + "_pager");
							
							if (_2b != 0) {
								$("<span id=\"" + _17.popupId + "_prev\">" + _17.prevText + "</span>").appendTo("#" + _17.popupId + "_gallery").click(function() {
									_26();
									var obj = arr[_2b - 1];
									$(obj).trigger("click");
								});
							}
							if (_2b < arr.length - 1) {
								$("<span id=\"" + _17.popupId + "_next\">" + _17.nextText + "</span>").appendTo("#" + _17.popupId + "_gallery").click(function() {
									_26();
									var obj = arr[_2b + 1];
									$(obj).trigger("click");
								});
							}
						}
					}
				});
			}
		});
	}
}

})(jQuery);